package com.yanqu.road.server.cmd.estatewar;

import com.yanqu.road.server.pb.EstateWarPb;
import com.yanqu.road.entity.estatewar.UserEstateFloor;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.EstateWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.List;

@Cmd(code = Protocol.S_ESTATE_WAR_RANK, desc = "乔迁风云榜单")
public class EstateWarRankCmd extends AbstractCommand {

	private int type;

	private List<UserEstateFloor> userEstateFloorList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		EstateWarProto.EstateWarRankReqMsg reqMsg = EstateWarProto.EstateWarRankReqMsg.parseFrom(packet.getBytes());
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		userEstateFloorList = EstateWarMgr.getEstateWarRankFloorList(type);
	}

	@Override
	public void sendData(GamePlayer player) {
		EstateWarProto.EstateWarFloorListMsg.Builder respMsg = EstateWarPb.parseEstateWarFloorListMsg(userEstateFloorList);
		player.sendPacket(Protocol.U_ESTATE_WAR_RANK, respMsg);
	}
}
